import pandas as pd

def line_data():
    df_first = pd.read_csv('static/data/第一产业增加值(亿元).csv', encoding='gbk')
    df_second = pd.read_csv('static/data/第二产业增加值(亿元).csv', encoding='gbk')
    df_third = pd.read_csv('static/data/第三产业增加值(亿元).csv', encoding='gbk')

    year = [i[:-1] for i in df_first.columns[1:]]
    first_line = [round(df_first[i].sum()) for i in df_first.columns[1:]]
    second_line = [round(df_second[i].sum()) for i in df_first.columns[1:]]
    third_line = [round(df_third[i].sum()) for i in df_first.columns[1:]]
    return {
        'year': year,
        'first_line': first_line,
        'second_line': second_line,
        'third_line': third_line,
    }


def geo_data():
    df_region = pd.read_csv('static/data/地区生产总值(亿元).csv', encoding='gbk')
    year = [i[:-1] for i in df_region.columns[1:]]
    data = [[{'name': j[0], 'value': j[1]} for j in df_region[['地区', i]].values] for i in df_region.columns[1:]]
    return {
        'year': year,
        'data': data
    }


def radar_data():
    df_nlmy = pd.read_csv('static/data/农林牧渔.csv', encoding='gbk')
    year = [i[:-1] for i in df_nlmy.columns[1:]]
    data = [df_nlmy[i].values.tolist()[1:] for i in df_nlmy.columns[1:]]
    data_max = [{'name':i,'value':max(df_nlmy[df_nlmy['指标'] == i].values.tolist()[0][1:])} for i in df_nlmy['指标'].values.tolist()[1:]]
    return {
        'year': year,
        'data': data,
        'data_max': data_max
    }


def pie_data():
    df_gnsczz = pd.read_csv('static/data/国内生产总值.csv', encoding='gbk')
    year = [i[:-1] for i in df_gnsczz.columns[1:]]
    data = [
        [{'name': j[0], 'value': j[1]} for j in zip(df_gnsczz.iloc[2:-1, 0].values, df_gnsczz.iloc[2:-1, :][i].values)]
        for i in df_gnsczz.columns[1:]]
    return {
        'year': year,
        'data': data
    }


def bar_data():
    df_s = pd.read_csv('static/data/市农林牧渔业增加值(亿元).csv', encoding='gbk')
    year = [i[:-1] for i in df_s.columns[1:]]
    data = [i for i in df_s.values.tolist()]
    return {
        'year': year,
        'data': data
    }
